﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'P_InsertPerson')
	BEGIN
		DROP  Procedure  [esf_sso].P_InsertPerson
	END

GO

CREATE Procedure [esf_sso].P_InsertPerson
	@pID					BIGINT OUTPUT
	,@pFirstName			VARCHAR (40)
	,@pSecondName			VARCHAR (40) = NULL
	,@pSurName				VARCHAR (40)
	,@pLastName				VARCHAR (40) = NULL
	,@pBirthDate			DATETIME = NULL
	,@pGenderID				BIGINT
	,@pIdentificationTypeID BIGINT
	,@pIdentificationNumber VARCHAR (20)
	,@pEmail				VARCHAR (160)
	,@pEnterpriseID			BIGINT = NULL
	,@pOtherEnterprise		VARCHAR (60) = NULL
	,@pProfession			VARCHAR (200) = NULL
	,@pPosition				VARCHAR (200) = NULL
AS

	INSERT INTO [esf_sso].[Person]
		([FirstName]
		,[SecondName]
		,[SurName]
		,[LastName]
		,[BirthDate]
		,[GenderID]
		,[IdentificationTypeID]
		,[IdentificationNumber]
		,[Email]
		,[EnterpriseID]
		,[OtherEnterprise]
		,Profession
		,Position)
     VALUES
         (@pFirstName
		,@pSecondName
		,@pSurName
		,@pLastName
		,@pBirthDate
		,@pGenderID
		,@pIdentificationTypeID
		,@pIdentificationNumber
		,@pEmail
		,@pEnterpriseID
		,@pOtherEnterprise
		,@pProfession
		,@pPosition)
		
	SET @pID = @@IDENTITY
	
GO